package cn.sumpu.app.guoguojie.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.sumpu.app.guoguojie.constant.BadgeType;
import cn.sumpu.app.guoguojie.constant.FamilyRole;
import cn.sumpu.app.guoguojie.util.Common;
import cn.sumpu.app.guoguojie.util.Experience;

public class Family implements Serializable {

	private static final long serialVersionUID = -8027443865127593199L;

	private String doorplate;
	private String nickname;
	private String avatar;
	private String province;
	private String city;
	private String county;
	private String town;
	private String address;
	private Integer integral;
	private Boolean isActive;
	private String imageServer;
	private String type;
	private Date gmtCreated;
	private Date gmtModified;
	private String introduction;
	private String skin;
	private String provinceCode;
	private String cityCode;
	private String countyCode;
	private String townCode;
	private Integer days = 0;
	private Date lastLoginTime;
	private String rookieReward;
	private String haveBaby;
	private List<Member> memberList;

	// 这家今天一共发表了多少条微博/日志（包括对别人微博/日志的评论）
	private Integer doingCommentCount = null;
	private Integer blogCommentCount = null;
	private Integer followCount = 0;
	private Integer fansCount = 0;
	private Integer loveCount = 0;

	// 取得等级的logo图片
	public String getLevelLogo() {
		return Experience.getLevelLogoByIntegral(integral);
	}

	// 根据积分取得等级
	public Integer getLevel() {
		return Experience.getLevelByIntegral(integral);
	}

	// 计算还有多少分可以升级
	public Integer getPoint() {
		return Experience.getPointByIntegral(integral);
	}

	// 计算积分/满分的百分比
	public double getPercentAll() {
		return Experience.getPercentAll(integral);
	}

	// 计算所处级别的百分比
	public Integer getPercent() {
		return Experience.getPercent(integral);
	}

	public Integer getDoingCommentCount() {
		return doingCommentCount;
	}

	public void setDoingCommentCount(Integer doingCommentCount) {
		this.doingCommentCount = doingCommentCount;
	}

	public Integer getBlogCommentCount() {
		return blogCommentCount;
	}

	public void setBlogCommentCount(Integer blogCommentCount) {
		this.blogCommentCount = blogCommentCount;
	}

	public Integer getDays() {
		return days;
	}

	public void setDays(Integer days) {
		this.days = days;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public String getRookieReward() {
		return rookieReward;
	}

	public void setRookieReward(String rookieReward) {
		this.rookieReward = rookieReward;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getDoorplate() {
		return doorplate;
	}

	public void setDoorplate(String doorplate) {
		this.doorplate = doorplate;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCounty() {
		return county;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Integer getIntegral() {
		return integral;
	}

	public void setIntegral(Integer integral) {
		this.integral = integral;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}

	public String getImageServer() {
		return imageServer;
	}

	public void setImageServer(String imageServer) {
		this.imageServer = imageServer;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Date getGmtCreated() {
		return gmtCreated;
	}

	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}

	public Date getGmtModified() {
		return gmtModified;
	}

	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public String getSkin() {
		return skin;
	}

	public void setSkin(String skin) {
		this.skin = skin;
	}

	public String getProvinceCode() {
		return provinceCode;
	}

	public void setProvinceCode(String provinceCode) {
		this.provinceCode = provinceCode;
	}

	public String getCityCode() {
		return cityCode;
	}

	public void setCityCode(String cityCode) {
		this.cityCode = cityCode;
	}

	public String getCountyCode() {
		return countyCode;
	}

	public void setCountyCode(String countyCode) {
		this.countyCode = countyCode;
	}

	public String getTownCode() {
		return townCode;
	}

	public void setTownCode(String townCode) {
		this.townCode = townCode;
	}

	public List<Member> getMemberList() {
		return memberList;
	}

	public void setMemberList(List<Member> memberList) {
		this.memberList = memberList;
	}

	public Integer getFollowCount() {
		return followCount;
	}

	public void setFollowCount(Integer followCount) {
		this.followCount = followCount;
	}

	public Integer getFansCount() {
		return fansCount;
	}

	public void setFansCount(Integer fansCount) {
		this.fansCount = fansCount;
	}

	public Integer getLoveCount() {
		return loveCount;
	}

	public void setLoveCount(Integer loveCount) {
		this.loveCount = loveCount;
	}

	public Member getFather() {
		if (memberList != null && memberList.size() > 0) {
			for (Member member : memberList) {
				if (FamilyRole.FATHER.getValue().equals(member.getRole())) {
					return member;
				}
			}
		}
		return null;
	}

	public Member getMother() {
		if (memberList != null && memberList.size() > 0) {
			for (Member member : memberList) {
				if (FamilyRole.MOTHER.getValue().equals(member.getRole())) {
					return member;
				}
			}
		}
		return null;
	}

	public List<Member> getBabyList() {
		List<Member> babyList = null;
		if (memberList != null && memberList.size() > 0) {
			babyList = new ArrayList<Member>();
			for (Member member : memberList) {
				if (FamilyRole.BABY.getValue().equals(member.getRole())) {
					babyList.add(member);
				}
			}
		}
		return babyList;
	}

	public String getHaveBaby() {
		return haveBaby;
	}

	public void setHaveBaby(String haveBaby) {
		this.haveBaby = haveBaby;
	}

	// 徽章大图
	public List<Badge> getAllBadge() {
		String str = rookieReward;
		List<Badge> list = new ArrayList<Badge>();
		for (int i = 0; str != null && i < str.length(); i++) {
			if (i > 0) {
				Badge badge = new Badge();
				String ind = String.valueOf(i);
				boolean have = false;
				String imgUrl = "imgs/xunzPic" + ind + ".png";
				if (i == 1) {
					if (str.charAt(0) == '0' || str.charAt(1) == '0') {
						have = false;
					} else {
						have = true;
					}
				}

				if (i > 1) {
					if (str.charAt(i) == '1') {
						have = true;
					} else {
						have = false;
					}
				}
				badge.setIndex(i);
				badge.setHave(have);
				badge.setTitle(BadgeType.getLabelByValue(ind));
				badge.setImgUrl(imgUrl);
				list.add(badge);
			}

		}

		return list;
	}
	
	// 徽章小图
	public List<Badge> getAllBadgeS() {
		String str = rookieReward;
		List<Badge> list = new ArrayList<Badge>();
		for (int i = 0;str != null && i < str.length(); i++) {
			if (i > 0) {
				Badge badge = new Badge();
				String ind = String.valueOf(i);
				boolean have = false;
				String imgUrl = "imgs/xunzPic" + ind + "_s_s.png";
				if (i == 1) {
					if (str.charAt(0) == '0' || str.charAt(1) == '0') {
						have = false;
					} else {
						have = true;
					}
				}

				if (i > 1) {
					if (str.charAt(i) == '1') {
						have = true;
					} else {
						have = false;
					}
				}
				badge.setIndex(i);
				badge.setHave(have);
				badge.setTitle(BadgeType.getLabelByValue(ind));
				badge.setImgUrl(imgUrl);
				list.add(badge);
			}

		}

		return list;
	}
	public List<Badge> getMyBadge() {
		String str = rookieReward;
		List<Badge> list = new ArrayList<Badge>();
		for (int i = 0; str != null && i < str.length(); i++) {
			if (i > 0) {
				String ind = String.valueOf(i);
				boolean have = false;
				String imgUrl = "imgs/xunzPic" + ind + "_s.png";
				//徽章1-4
				if (i <= 4) {
					if (i == 1) {
						if (str.charAt(0) == '0' || str.charAt(1) == '0') {
							imgUrl = "imgs/xunzPic" + ind + "_h.png";
							have = false;
						} else {
							have = true;
						}
					}
					if (i > 1 && i <= 4) {
						if (str.charAt(i) == '0') {
							imgUrl = "imgs/xunzPic" + ind + "_h.png";
							have = false;
						} else {
							have = true;
						}
					}
				}
				//徽章5-14
				if(i>4){
					if (str.charAt(i) == '0') {
						have = false;
					} else {
						have = true;
					}
				}
				Badge badge = new Badge();
				badge.setIndex(i);
				badge.setHave(have);
				badge.setTitle(BadgeType.getLabelByValue(ind));
				badge.setImgUrl(imgUrl);
				list.add(badge);
			}

		}

		return list;
	}

	public Integer getBadgeCount() {
		int num = 0;
		if(Common.emptyStr(rookieReward)){
			return num;
		}
		if (rookieReward.charAt(0) == '1' && rookieReward.charAt(1) == '1') {
			num = num + 1;
		}
		String str = rookieReward.substring(2);
		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if (c == '1') {
				num++;
			}
		}
		return num;
	}

}
